package com.huizhonglm.diap.ui.wallet;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.RevenueInfoOld;
import com.huizhonglm.diap.core.utils.UserUtil;
import com.huizhonglm.diap.presenters.wallet.RcmRevenueOldPresenter;
import com.huizhonglm.diap.ui.BaseActivity;
import com.huizhonglm.diap.ui.wallet.iView.RcmRevenueOldIView;
import com.huizhonglm.diap.widget.LoadView;

import java.util.List;

/**
 * 收益查看页面
 */
public class RcmRevenueOldActivity extends BaseActivity implements RcmRevenueOldIView, LoadView.OnLoadAgainListener {

    private ListView mListView;
    private LoadView loadView;
    private TextView totalTxt;

    private String userID;
    private RcmRevenueOldPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rcm_revenue_old);
        setBackEvent(this, null);
        userID = UserUtil.getUserId();
        mPresenter = new RcmRevenueOldPresenter(this);
        assignViews();
        onLoadAgain();
 }

    @Override
    protected void assignViews() {
        loadView = (LoadView) findViewById(R.id.load_view);
        mListView = (ListView) findViewById(R.id.revenue_list);
        totalTxt = (TextView) findViewById(R.id.total_revenue_txt);
        loadView.setDataView(mListView, this);
    }

    @Override
    public void onLoadAgain() {
        mPresenter.loadData(userID);
    }

    @Override
    public void onLoadDataSuccess(List<RevenueInfoOld> data) {
        if (!EmptyUtil.isEmpty(data)) {
            double total = 0;
            for (RevenueInfoOld info : data) {
                total += info.getDividend();
            }
            totalTxt.setText(String.format("%.2f",total));
            RcmRevenueOldAdapter adapter = new RcmRevenueOldAdapter(this, data);
            mListView.setAdapter(adapter);
            loadView.showDataView();
        } else {
            loadView.showEmptyView("当前无收益信息");
        }
    }

    @Override
    public void onLoadDataFailure() {
        loadView.showErrorView();
    }
}
